package itool

import (
	"fmt"
	"path/filepath"
)

func RepeatFilename(fnm map[string]int, filename string) string {
	if i, ok := fnm[filename]; ok {
		fnm[filename] = i + 1
		ext := filepath.Ext(filename)
		repeat := fmt.Sprintf("(%d)", i)
		return filename[0:len(filename)-len(ext)] + repeat + ext
	}
	fnm[filename] = 1
	return filename
}

func ReplaceFileExt(filename string, new string) string {
	old := filepath.Ext(filename)
	return filename[0:len(filename)-len(old)] + new
}
